
local frames = {
    ['资源栏'] = japi.SimpleFrameFindByName("ResourceBarFrame",0),
    ['资源栏黄金'] = japi.SimpleFontStringFindByName("ResourceBarGoldText",0),
    ['资源栏木材'] = japi.SimpleFontStringFindByName("ResourceBarLumberText",0),
    ['资源栏人口'] = japi.SimpleFontStringFindByName("ResourceBarSupplyText",0),
    ['维修提示'] = japi.SimpleFontStringFindByName("ResourceBarUpkeepText",0),
}
--隐藏原生
for name, id in pairs(frames) do 
    japi.FrameClearAllPoints(id)
    japi.FrameSetPoint(id, 0, japi.GetGameUI(), 0, 1, 1)
end 

local Resources = {
    {'金币',[[UI\Feedback\Resources\ResourceGold.blp]]},
    {'木材',[[UI\Feedback\Resources\ResourceLumber.blp]]},
    {'杀敌',[[UI\Feedback\Resources\ResourceUndead.blp]]},
}
local w,h = 180,36
local gap = 20
local panel = class.panel.create('',0,0,1,1)
local buttons = {}
for a,da in ipairs(Resources) do
    local button = panel:add_button('',(a-1) * (w + gap) + 1130,-5,w,h)
    button.name = da[1]
    button.icon = button:add_panel(da[2],10,10,36,24)
    button.text = button:add_text('',0,5,nil,nil,10,6)
    button.text2 = button:add_text('',0,35,nil,nil,10,6)
    buttons[a] = button
end

function panel:on_button_mouse_enter(button)
    local name = button.name
    if name=='金币' then
        button:tooltip(name,'金币是最泛用的货币')
    elseif name=='木材' then
        button:tooltip(name,'木材用于抽卡')
    elseif name=='杀敌' then
        button:tooltip(name,'木材用于黑店购买')
    end
end

function panel:update()
    local locplayer = ac.player.self
    local hero = locplayer.hero
    for _,button in ipairs(buttons) do
        local name = button.name
        if name=='金币' then
            button.text:set_text(('%0.0f'):format(locplayer:get('金币')))
            local ex = hero and hero:get('每秒金币')
            if ex then
                button.text2:set_text(('|cffffff00+%0.1f/s|r'):format(ex))
            end
        elseif name=='木材' then
            button.text:set_text(('%0.0f'):format(locplayer:get('木材')))
            local ex = hero and hero:get('每秒木材')
            if ex then
                button.text2:set_text(('|cff00ff00+%0.1f/s|r'):format(ex))
            end
        elseif name=='杀敌' then
            button.text:set_text(('%0.0f'):format(locplayer:get('杀敌')))
            local ex = hero and hero:get('每秒杀敌')
            if ex then
                button.text2:set_text(('|cffff0000+%0.1f/s|r'):format(ex))
            end
        end
    end
end

ac.hardware:event '界面绘制'(function()
    panel:update()
end)